﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;

namespace 生产计划批量打印工具
{
    public partial class frmPrintSettings : Form
    {
        public frmPrintSettings()
        {
            InitializeComponent();
        }

        private void iniPrinterNames()
        {
            cmbPrinterName.Items.Clear();
            try
            {
                foreach (string Printer in PrinterSettings.InstalledPrinters)
                {
                    cmbPrinterName.Items.Add(Printer);
                }
            }
            catch
            {
                MessageBox.Show("获取打印机名错误！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
        }

        private void iniNuds()
        {
            nudG_Price_Copies.Value  = 生产计划批量打印工具.Properties.Settings.Default.G_Price_Copies;
            nudG_NoPrice_Copies.Value = 生产计划批量打印工具.Properties.Settings.Default.G_NoPrice_Copies;
            nudJ_Price_Copies.Value = 生产计划批量打印工具.Properties.Settings.Default.J_Price_Copies;
            nudJ_NoPrice_Copies.Value = 生产计划批量打印工具.Properties.Settings.Default.J_NoPrice_Copies;
            nudM_Price_Copies.Value = 生产计划批量打印工具.Properties.Settings.Default.M_Price_Copies;
            nudM_NoPrice_Copies.Value = 生产计划批量打印工具.Properties.Settings.Default.M_NoPrice_Copies;
        }

        private void btnSetPrinterName_Click(object sender, EventArgs e)
        {
            if (cmbPrinterName.Text.Length > 0)
            {
                生产计划批量打印工具.Properties.Settings.Default.PrinterName = cmbPrinterName.Text;
                生产计划批量打印工具.Properties.Settings.Default.Save();
            }
            else
            {
                MessageBox.Show("新打印机名称不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
            }
        }

        private void frmPrintSettings_Load(object sender, EventArgs e)
        {
            iniPrinterNames();
            iniNuds();
        }

        private void btnSetCopies_Click(object sender, EventArgs e)
        {
            生产计划批量打印工具.Properties.Settings.Default.G_Price_Copies=Convert.ToInt16 ( nudG_Price_Copies.Value);
            生产计划批量打印工具.Properties.Settings.Default.G_NoPrice_Copies=Convert.ToInt16 (nudG_NoPrice_Copies.Value);
            生产计划批量打印工具.Properties.Settings.Default.J_Price_Copies = Convert.ToInt16 (nudJ_Price_Copies.Value) ;
            生产计划批量打印工具.Properties.Settings.Default.J_NoPrice_Copies=Convert.ToInt16 (nudJ_NoPrice_Copies.Value);
            生产计划批量打印工具.Properties.Settings.Default.M_Price_Copies=Convert.ToInt16 (nudM_Price_Copies.Value);
            生产计划批量打印工具.Properties.Settings.Default.M_NoPrice_Copies=Convert.ToInt16 (nudM_NoPrice_Copies.Value);
            生产计划批量打印工具.Properties.Settings.Default.Save();
            MessageBox.Show("设置保存成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
        }
    }
}